// log
package feedback

import (
	"encoding/json"

	"net/http"

	"awfan.cn/utils"

	"gopkg.in/mgo.v2"
)

func create(format string, w http.ResponseWriter, body []byte, db *mgo.Database) {
	data := FEEDBACK_XML{}

	if err := json.Unmarshal(body, &data); err != nil {
		utils.WriteError(format, 404, err.Error(), w)
		return
	}

	if err := utils.Setting.Smtp.Mail("feedback", data.Nick, utils.Setting.Smtp.Account,
		utils.Setting.Feedback, data.Description, data.Attachment); err != nil {
		utils.WriteError(format, 500, err.Error(), w)
		return
	}

	utils.WriteEmpty(format, w)
}
